<template>
  <div>
    <el-form label-width="130px" :model="form" ref="inationRef">
      <div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="合同编号：" prop="contractCode">
              {{ form.contractCode || "/" }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同名称：" prop="contractName">
              {{ form.contractName || "/" }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="合同类型：" prop="contractType">
              <dict-tag
                :options="sys_contract_type"
                :value="form.contractType"
                v-if="form.contractType"
              />
              <span v-else>/</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="紧急程度：" prop="degree">
              <dict-tag
                :options="sys_degree"
                :value="form.degree"
                v-if="form.degree"
              />
              <span v-else>/</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="重大项目：" prop="projectId">
              {{
                proxy.getItemByArray(
                  projectList,
                  "value",
                  form.projectId,
                  "label"
                ) || "/"
              }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="业务员：" prop="busUser">
              {{
                proxy.getItemByArray(
                  userList,
                  "userId",
                  form.busUser,
                  "nickName"
                ) || "/"
              }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="采样来源：" prop="sampleSource">
              <dict-tag
                :options="sys_sample_source"
                :value="form.sampleSource"
                v-if="form.sampleSource"
              />
              <span v-else>/</span>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-input v-if="form.sampleSource == 4" />
          </el-col>
          <el-col :span="12">
            <el-form-item label="检后样品处置：" prop="sampleAfter">
              <dict-tag
                :options="sys_sample_handle"
                :value="form.sampleAfter"
                v-if="form.sampleAfter"
              />
              <span v-else>/</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="合同开始时间：" prop="beginDate">
              {{ form.beginDate || "/" }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="要求完成时间：" prop="requireDate">
              {{ form.requireDate || "/" }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="协商条款：" prop="orgEmail">
              {{
                proxy.getItemByArrays(
                  sys_xstk_type,
                  "value",
                  form.xstks,
                  "label"
                ) || "/"
              }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="当前合同状态：" prop="orgEmail"
              >编辑中</el-form-item
            >
          </el-col>
        </el-row>
      </div>
      <!-- 委托单位信息 -->
      <div>
        <el-row>
          <el-col :span="3">
            <p class="pinformation">委托单位信息</p>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="委托单位名称：" prop="wtCustomName">
              {{ form.wtCustomName || "/" }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="委托单位地区：" prop="wtCityName">
              {{ form.wtCityName || "/" }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="委托单位地址：" prop="wtAddress">
              {{ form.wtAddress || "/" }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="联系人：" prop="wtContacts">
              {{ form.wtContacts }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="联系电话：" prop="wtPhonenumber">
              {{ form.wtPhonenumber }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报告领取方式：" prop="wtReportType">
              <dict-tag
                :options="sys_report_type"
                :value="form.wtReportType"
                v-if="form.wtReportType"
              />
              <span v-else>/</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="电子邮箱：" prop="wtEmail">
              {{ form.wtEmail || "/" }}
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <!-- 受检单位信息 -->
      <div>
        <el-row style="margin-bottom: 5px">
          <el-col :span="3">
            <p class="pinformation">受检单位信息</p>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="受检单位名称：" prop="sjCustomName">
              {{ form.sjCustomName || "/" }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="受检单位地区：" prop="sjCityName">
              {{ form.sjCityName || "/" }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="受检单位地址：" prop="sjAddress">
              {{ form.sjAddress || "/" }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="联系人：" prop="sjContacts">
              {{ form.sjContacts || "/" }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="联系电话：" prop="sjPhonenumber">
              {{ form.sjPhonenumber || "/" }}
            </el-form-item>
          </el-col>
        </el-row>
      </div>

      <div>
        <el-row style="margin-bottom: 5px; height: 25px">
          <el-col :span="3">
            <p class="pinformation">合同文档生成</p>
          </el-col>
          <el-col :span="3">
            <p
              style="
                font-size: 14px;
                margin-top: 0px;
                margin-bottom: 6px;
                font-weight: 500;
              "
            >
              共 {{ form.contractFileList.length }} 条数据
            </p>
          </el-col>
        </el-row>
        <el-table :data="form.contractFileList" v-loading="loading1">
          <el-table-column label="文件编号" align="center" prop="fileCode" />
          <el-table-column label="文件名称" align="center" prop="fileMc">
            <template #default="scope">
              <span
                @click="proxy.downloadFile(scope.row.fileList, 'local')"
                class="fileNameHover"
                >{{ scope.row.fileMc }}</span
              >
            </template>
          </el-table-column>
          <el-table-column label="上传时间" align="center" prop="createTime" />
          <el-table-column
            label="上传人"
            align="center"
            prop="createUserName"
          />
        </el-table>
      </div>
      <div>
        <el-row style="margin-bottom: 5px">
          <el-col :span="3">
            <p class="pinformation">客户合同附件</p>
          </el-col>
          <el-col :span="3">
            <p
              style="
                font-size: 14px;
                margin-top: 0px;
                margin-bottom: 6px;
                font-weight: 500;
              "
            >
              共 {{ form.customFileList.length }} 条数据
            </p>
          </el-col>
        </el-row>
        <el-table :data="form.customFileList" v-loading="loading2">
          <el-table-column label="文件编号" align="center" prop="fileCode" />
          <el-table-column label="文件名称" align="center" prop="fileMc">
            <template #default="scope">
              <span
                @click="proxy.downloadFile(scope.row.fileList, 'local')"
                class="fileNameHover"
                >{{ scope.row.fileMc }}</span
              >
            </template>
          </el-table-column>
          <el-table-column label="上传时间" align="center" prop="createTime" />
          <el-table-column
            label="上传人"
            align="center"
            prop="createUserName"
          />
        </el-table>
      </div>
    </el-form>
  </div>
</template>

<script setup>
import { listUser, getContract } from "@/api/contract/check";
import { getFileListAPI } from "@/api/resource/instrumentItem";
const { proxy } = getCurrentInstance();
const {
  sys_degree,
  sys_xstk_type,
  sys_sample_source,
  sys_report_type,
  sys_sample_handle,
} = proxy.useDict(
  "sys_xstk_type",
  "sys_degree",
  "sys_sample_source",
  "sys_report_type",
  "sys_sample_handle"
);
const {
  sys_contract_type,
} = proxy.useOrgDict(
  "sys_contract_type",
);
const loading1 = ref(false);
const loading2 = ref(false);

const projectList = ref([
  { value: 0, label: "否" },
  { value: 1, label: "是" },
]);

const props = defineProps({
  echo: {
    type: String,
  },
});

const data = reactive({
  form: {
    contractType: 1,
    degree: 2,
    projectId: 1,
    customFileList: [],
    contractFileList: [],
  },
});
const { form } = toRefs(data);

function reset() {
  nextTick(() => {
    proxy.resetForm("inationRef");
    delete form.value.contractId;
  });
}

function echo() {
  getContract(props.echo).then((res) => {
    form.value = res.data;
    form.value.xstks = form.value.xstk ? form.value.xstk.split(",") : [];
    // 查询合同文档
    form.value.contractFileList = [];
    form.value.customFileList = [];
    loading1.value = true;
    loading2.value = true;
    getFileListAPI({ groupId: form.value.contractId, fileType: 25 }).then(
      (res) => {
        loading1.value = false;
        form.value.contractFileList = res.data;
      }
    );
    // 查询客户文件
    getFileListAPI({ groupId: form.value.contractId, fileType: 26 }).then(
      (res) => {
        loading2.value = false;
        form.value.customFileList = res.data;
      }
    );
  });
}

const emits = defineEmits(["renovate"]);

const userList = ref([]);
listUser().then((res) => {
  userList.value = res.data;
});

defineExpose({
  reset,
  echo,
});
</script>

<style></style>
